package com.etogc.flycobanner;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.etogc.flycobanner.widget.Banner.BaseIndicatorBanner;
import com.etogc.groupchat.R;
import com.etogc.util.GcUrl;
import com.etogc.util.ImageUtils;

import java.util.HashMap;


public class SimpleImageBanner extends BaseIndicatorBanner<HashMap<String, String>, SimpleImageBanner> {

    private ColorDrawable colorDrawable;

    public SimpleImageBanner(Context context) {
        this(context, null, 0);
    }

    public SimpleImageBanner(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SimpleImageBanner(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        colorDrawable = new ColorDrawable(Color.parseColor("#555555"));
    }

    @Override
    public void onTitleSlect(TextView tv, int position) {
        final HashMap<String, String> map = mDatas.get(position);
        if (!TextUtils.isEmpty(map.get(""))) {
            tv.setText(String.valueOf(map.get("title")) + position);
        }
    }

    @Override
    public View onCreateItemView(int position) {
        View inflate = View.inflate(mContext, R.layout.item_banner, null);
        ImageView iv = inflate.findViewById(R.id.picture);

        if (mDatas != null) {
            HashMap<String, String> map = mDatas.get(position);
            String imgUrl = ImageUtils.getImageUrl(String.valueOf(map.get("photo")));
//            String imgUrl = String.valueOf(map.get("photo"));
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            if (!TextUtils.isEmpty(imgUrl)) {
                ImageUtils.setImage2(mContext, imgUrl, iv);
            } else {
                iv.setImageDrawable(colorDrawable);
            }
        }

        return inflate;
    }
}
